#include "polygonizer.h"

namespace sol9
{

	polygon_ptr polygonizer::create(u32 point, f32 radius)
	{
		polygon_ptr p(new polygon);
		vertices& v = p->v;
		v.resize(point);

		u32 i = 0;
		f32 d = 2.0f * sol9::PI / point;

		auto calc = [&](vertices::value_type& p)
		{
			f32 r = d * i++;
			p.x = radius * std::sinf(r);
			p.y = radius * std::cosf(r);
		};

		auto end = v.end();
		std::for_each(v.begin(), end, calc);

		return p;
	}

} // namespace sol9